<!DOCTYPE html>
<html lang="en">

<head>
    <title>html5</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1"> </head>

<body>
    <p id="cur_pos">您当前位置：</p>
    <script>
        function showpos(pos) {
            var p = document.getElementById("cur_pos")
            p.innerHTML = "您当前位置：<br/>纬度：" + pos.coords.latitude + 
            "<br />经度" + pos.coords.longitude;
        }
        // 获取位置时间比较久，函数传入获取位置成功时的回调函数
        navigator.geolocation.getCurrentPosition(showpos)
    </script> </body>

</html>